﻿using AutoMapper;
using MediatR;
using MyMES.Domain.zyy;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Writer.API.Application.CommendHandlers.Inventorylists;

namespace MyMES.Writer.API.Application.Commends.Inventorylists
{
    public class AddInverlistHandler : IRequestHandler<AddInverlistcommand, APIResult<Inventorylist>>
    {
        private readonly IMapper mapper;
        private readonly IBaseRepository<Inventorylist> repository;

        public AddInverlistHandler(IMapper mapper,IBaseRepository<Inventorylist> repository)
        {
            this.mapper = mapper;
            this.repository = repository;
        }
        public async Task<APIResult<Inventorylist>> Handle(AddInverlistcommand request, CancellationToken cancellationToken)
        {
            APIResult<Inventorylist> result = new APIResult<Inventorylist>();
            result.Code = APIEnum.添加成功;
            result.Msg = "添加成功";
             var model=mapper.Map<Inventorylist>(request);
            string str = "insert Inventorylist (InventoryId,InboundTime,OutboundTime,WarehouseName,InventoryName,InventoryNumber,InventoryNum,InventSpecifications,Shifou) values (@InventoryId,@InboundTime,@OutboundTime,@WarehouseName,@InventoryName,@InventoryNumber,@InventoryNum,@InventSpecifications,@Shifou)";
            await repository.Insert(model,str);
            return result;

        }
    }
}
